<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript">
Ext.ns('catalog.catalog.adaugaAbsenta');
FormPanel = function() {

	FormPanel.superclass.constructor.call(this, {
        id: 'addAbsenceForm',
        bodyBorder: false,
        frame: true,
        style:'padding:1px',
        items: [{
            xtype: 'fieldset',
            labelWidth: 150,
            title: this.addAbsenceText,
            layout: 'form',
            collapsible: true,
            defaults: {width: 210},
            defaultType: 'textfield',
            autoHeight: true,
            items: [{
            	name:'absence.date',
            	xtype:'datefield',
                fieldLabel: this.dateText,
                allowBlank:false
            },
             new Ext.form.ComboBox({
                typeAhead: true,
                triggerAction: 'all',
                lazyRender:true,
                name:'absenceState',
                fieldLabel:this.valueText,
                mode: 'local',
                store: new Ext.data.ArrayStore({
                id: 0,
                fields: [
                'myId',
                'displayText'
                ],
                data: [[1, 'Nemotivata'], [2, 'Motivata']]
                }),
                valueField: 'myId',
                displayField: 'displayText',
                value:1
                }),
             {
                 name:'absence.comment',
                 xtype:'textarea',
                 fieldLabel: this.commentText
             }
            ]
        },{
            buttonAlign:'center',
            buttons: [{
	            text: mbLocale.submitButton,
	            scope:this,
	            formBind:true,
	            handler: function(){
	                var URL = 'saveAbsence.action?studentId=' +<%=request.getParameter("studentId")%>;

	                this.getForm().submit({
	                    url: URL,
	                    method: 'POST',
	                    disabled:true,
	                    waitMsg: mbLocale.waitingMsg,
//	                    params:params,
	                    success: function(form, action) {
	                        obj = Ext.util.JSON.decode(action.response.responseText);
	                        showMsg('success', obj.message);
	                        Ext.WindowMgr.getActive().close();
	                    },
	                    failure: function(form, action) {
	                        try{
	                            obj = Ext.util.JSON.decode(action.response.responseText);
	                            showMsg('failure', obj.message);
	                        }catch(ex){return;}
	                    }
	                });
	            }
	        },{
	            text: mbLocale.closeButton,
	            handler: function() {Ext.WindowMgr.getActive().close();}
            }]
        }]
    });
};

catalog.catalog.adaugaAbsenta.FormPanel=Ext.extend(FormPanel, Ext.FormPanel, {
    addAbsenceText:'Adauga absenta',
    idText:'ID',
    valueText:'Stare',
    dateText:'Data',
    commentText:'Comentariu'

});

try{ adaugaAbsentaLocale(); } catch(e){}

Ext.onReady(function() {
    Ext.QuickTips.init();
    Ext.form.Field.prototype.msgTarget = 'side';

    Ext.WindowMgr.getActive().add(new catalog.catalog.adaugaAbsenta.FormPanel());
    Ext.WindowMgr.getActive().doLayout();
});
</script>